package ooday03;
/** 引用类型数组的演示 */
public class RefArrayDemo {
    public static void main(String[] args) {

        /*
        //声明Dog型数组，包含3个元素，每个元素都是Dog型，默认值为null
        Dog[] dogs = new Dog[3];
        //声明Chick型数组，包含3个元素，每个元素都是Chick型，默认值为null
        Chick[] chicks = new Chick[3];
        //声明Fish型数组，包含2个元素，每个元素都是Fish型，默认值为null
        Fish[] fish = new Fish[2]; **/

        Dog[] dogs = new Dog[3];
        Chick[] chicks = new Chick[2];
        Fish[] fish = new Fish[4];
        //动物：狗
        dogs[0] = new Dog("小白", 3,"白");
        dogs[1] = new Dog("小黑", 2,"黑");
        dogs[2] = new Dog("小红", 2,"红");
        //动物：鸡
        chicks[0] = new Chick("小白",2,"黄鸡");
        chicks[1] = new Chick("大白",2,"黑鸡");
        //动物：鱼
        fish[0] = new Fish("锦鲤1",1,"玄红");
        fish[1] = new Fish("锦鲤2",1,"玄红");
        fish[2] = new Fish("锦鲤3",1,"玄红");
        fish[3] = new Fish("锦鲤4",1,"玄红");

        //输出第一个狗狗的姓名
        System.out.println(dogs[0].name);

        for (int i = 0; i < dogs.length; i++) { //遍历引用类型数组Dog
            System.out.println(dogs[i].name);//输出每只  狗 的名字
            dogs[i].eat();//每只狗吃饭
        }
        for (int i = 0; i < chicks.length ; i++) {//遍历引用类型数组Chick
            System.out.println(chicks[i].age);//输出每只  鸡 的年龄
            chicks[i].drink();//每只鸡喝
        }
        for (int i = 0; i < fish.length ; i++) {//遍历引用类型数组Fish
            System.out.println(fish[i].color);//输出每只  鱼 的颜色
            fish[i].swim();//每只鱼都仰泳
        }



    }
}
